﻿setTimeout(() => {
	console.log('成功加载猫国仓库管理员 (　o=^•ェ•)o　┏━┓')

	_wts.createSubgrade()
	_wts.setTitle('猫国仓库管理员')

	const config = {
		increase: 10 ** 10, // 每次增加的资源数量
	}

	const resourcesKey = 'com.nuclearunicorn.kittengame.savedata'
	const contentLayer = _wts.getContainer()
	const collectCatnipButton = document.querySelector('.bldGroupContainer').children[0].children[0].children[0].children[0].children[0]

	const resourcesTable = { // 名称映射表，增加这里的条目可以增加对应的资源按钮
		'猫薄荷': 'catnip',
		'木材': 'wood',
		'矿物': 'minerals',
		'煤': 'coal',
		'铁': 'iron',
		'钛': 'titanium',
		'黄金': 'gold',
		'石油': 'oil',
		'铀': 'uranium',
		// '难得素': 'unobtainium',
		// '反物质': 'antimatter',
		'喵力': 'manpower',
		'科学': 'science',
		'文化': 'culture',
		'信仰': 'faith',
		'斑马': 'zebras',
		'星图': 'starchart',
		'毛皮': 'furs',
		'象牙': 'ivory',
		'香料': 'spice',
		'独角兽': 'unicorns',
		'眼泪': 'tears',
		'时间水晶': 'timeCrystal',
		'遗物': 'relic',
		'虚空': 'void',
		// '包装纸': 'wrappingPaper',
		'木梁': 'beam',
		'石板': 'slab',
		'金属板': 'plate',
		'钢': 'steel',
		'混凝土': 'concrate',
		'齿轮': 'gear',
		'合金': 'alloy',
		'船': 'ship',
		'邮轮': 'tanker',
		'煤油': 'kerosene',
		'脚手架': 'scaffold',
		'羊皮纸': 'parchment',
		'手稿': 'manuscript',
		'概要': 'compedium',
		'蓝图': 'blueprint',
		'钍': 'thorium',
		'巨石': 'megalith',
	}

	let timer = null
	let clickCounter = 0

	// 创建资源按钮组
	const createAllAddResourcesButton = () => {
		const domCache = []
		for (let cnNameKey in resourcesTable) {
			const enName = resourcesTable[cnNameKey]
			const index = nameToGetIndex(enName)
			const btn = generateButton(cnNameKey, index)

			domCache.push(btn)
		}

		for (let dom of domCache) {
			contentLayer.appendChild(dom)
		}
	}

	// 生成一个按钮并返回
	const generateButton = (cnName, resourcesIndex) => {
		const btn = document.createElement('button')
		const title = `来 ${formatSize(config.increase)} ${cnName}`
		btn.innerText = title
		btn.style.margin = 3 + 'px'
		btn.style.fontSize = 10 + 'px'

		btn.onclick = () => {
			saveGameAllData()
			indexToAddResources(resourcesIndex)
			location.reload()
		}

		return btn
	}

	// 根据英文命获取资源索引
	const nameToGetIndex = (enName) => {
		let d = JSON.parse(localStorage.getItem(resourcesKey))
		for (let i = 0; i < d.resources.length; i++) {
			if (d.resources[i].name == enName) {
				return i
			}
		}
	}

	// 根据资源索引增加资源
	const indexToAddResources = (index) => {
		let data = JSON.parse(localStorage.getItem(resourcesKey))
		data.resources[index].value += config.increase
		localStorage.setItem(resourcesKey, JSON.stringify(data))
	}

	// 手动触发保存数据事件
	const saveGameAllData = () => {
		document.querySelector('.links-block').children[0].click()
	}

	// 创建不道德的巅峰成就按钮
	const createImmoralityButton = () => {
		const btn = document.createElement('button')
		const title = `不道德`
		btn.innerText = title
		btn.style.margin = 3 + 'px'
		btn.style.fontSize = 10 + 'px'

		btn.onclick = () => {
			timer = setInterval(() => {
				collectCatnipButton.click()
				clickCounter++
				if (clickCounter > 3000) {
					clearInterval(timer)
					clickCounter = 0
				}
			}, 50)
		}
		contentLayer.appendChild(btn)
	}

	// 主函数
	const main = () => {
		saveGameAllData()
		createAllAddResourcesButton()
		createImmoralityButton()
	}


	main()

}, 1 * 1000)

